<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

/**
 * @property bool $pay_status 支付状态:1=待支付,2=待核销,3=已完成,4=已过期
 * @property float $pay_amount 支付金额
 * @property int $deletetime
 * @property int $detail_id 坑位
 * @property int $id
 * @property int $paytime 支付时间
 * @property int $qrofftime 核销时间
 * @property int $user_id 用户
 * @property string $business_hours 营业时间
 * @property string $createtime
 * @property string $day 日期
 * @property string $off_sn 核销编号
 * @property string $order_sn 订单编号
 * @property-read \app\model\PuddleDetail $detail
 * @property-read mixed $pay_status_text
 * @property-read mixed $paytime_text
 * @method static \think\db\Query onlyTrashed()
 * @method static \think\db\Query withTrashed()
 * @mixin \think\Model
 */
class PuddleOrders extends Model
{
	use SoftDelete;
	//
	protected $createTime = 'createtime';
	protected $updateTime = 'updatetime';
	protected $deleteTime = 'deletetime';
	protected $append = [
		'paytime_text',
		'pay_status_text',
	];
	
	function detail()
	{
		return $this->belongsTo(PuddleDetail::class,'detail_id');
	}
	
	public function getPayStatusTextAttr($value, $data)
	{
		$value = $value ? $value : ($data['pay_status'] ?? '');
		$list = ['1' => '待支付', '2' => '待核销', '3' => '已完成', '4' => '已过期'];
		return $list[$value] ?? '';
	}
	
	function getPaytimeTextAttr($value,$data)
	{
		$value = $value ?? ($data['paytime'] ?? "");
		return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
	}
}
